package test23.classload_;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ClassLoad02 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入key");
        String key = scanner.next();
        switch (key){
            case "1":
                Dog dog = new Dog();
                dog.cry();
                break;
            case "2":
                //反射-->动态加载
                Class<?> cls = Class.forName("Person");//加载Person类[动态加载]
                Object o = cls.newInstance();
                Method hi = cls.getMethod("hi");
        }
    }
}
//因为new Dog()是静态加载，因此必须编写Dog,否则会报错
//Person类是动态加载，所以，没有编写Person类也不会报错，只有当动态加载该类时，才会报错
class Dog{
    public void cry(){
        System.out.println("小狗叫");
    }
}

